﻿using System.Threading.Tasks;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.UI.Navigation;
using YunxSoft.Abp.LanguageManagement.Localization;
using YunxSoft.Abp.LanguageManagement.Permissions;
using static Volo.Abp.UI.Navigation.DefaultMenuNames.Application;

namespace YunxSoft.Abp.LanguageManagement.Web.Menus;

public class LanguageManagementMenuContributor : IMenuContributor
{
    public async Task ConfigureMenuAsync(MenuConfigurationContext context)
    {
        if (context.Menu.Name == StandardMenus.Main)
        {
            await ConfigureMainMenuAsync(context);
        }
    }

    private Task ConfigureMainMenuAsync(MenuConfigurationContext context)
    {
        if (context.Menu.Name != StandardMenus.Main)
        {
            return Task.CompletedTask;
        }

        var l = context.GetLocalizer<LanguageManagementResource>();
        
        var languageManagementMenuItem = new ApplicationMenuItem(LanguageManagementMenus.Prefix, l["Menu:Languages"], icon: "fa fa-globe");
        languageManagementMenuItem.AddItem(new ApplicationMenuItem(LanguageManagementMenus.Languages, l["Languages"], url: "~/LanguageManagement/Languages").RequirePermissions(LanguageManagementPermissions.Languages.Default));
        languageManagementMenuItem.AddItem(new ApplicationMenuItem(LanguageManagementMenus.LanguageTexts, l["LanguageTexts"], url: "~/LanguageManagement/LanguageTexts").RequirePermissions(LanguageManagementPermissions.LanguageTexts.Default));
        context.Menu.GetAdministration().AddItem(languageManagementMenuItem);
        
        return Task.CompletedTask;
    }
}
